Malaysia Covid19 Cases Updates

Prepared By: Zahiruddin Zahidanishah

In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
import dataframe_image as dfi
import adjustText as aT
from jupyterthemes import jtplot
#import requests
import cufflinks as cf
#from bs4 import BeautifulSoup as bs
jtplot.style(theme='monokai', context='notebook', ticks=True, grid=False) 
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot 
init_notebook_mode(connected=True)
cf.go_offline()

from IPython.display import display_html
def display_side_by_side(*args):
    html_str=''
    for df in args:
        html_str+=df.to_html()
    display_html(html_str.replace('table','table style="display:inline"'),raw=True)
In [2]:
#Covid19 Malaysia States Dataset from MOH, Malaysia Github accounts 
df_states_cases = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_state.csv')
df_states_deaths = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_state.csv')
df_states_hosp = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/hospital.csv')
df_states_icu = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/icu.csv')
df_states_pkrc = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/pkrc.csv')
df_states_test = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/tests_state.csv')
df_states_vaksin = pd.read_csv('https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_state.csv')
df_states_pop = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/static/population.csv')
In [3]:
df_hosp_daily = df_states_hosp.groupby('date').sum().reset_index()
df_hosp_daily['admitted_covid_cum'] = df_hosp_daily['admitted_covid'].cumsum()
df_hosp_daily['discharged_covid_cum'] = df_hosp_daily['discharged_covid'].cumsum()
df_icu_daily = df_states_icu.groupby('date').sum().reset_index()
df_icu_daily['icu_covid_cum'] = df_icu_daily['icu_covid'].cumsum()
df_pkrc_daily = df_states_pkrc.groupby('date').sum().reset_index()
df_pkrc_daily['admitted_covid_cum'] = df_pkrc_daily['admitted_covid'].cumsum()
df_pkrc_daily['discharged_covid_cum'] = df_pkrc_daily['discharged_covid'].cumsum()
In [4]:
#Selecting the required columns
df_states_cases = df_states_cases[['date','state','cases_new','cases_recovered','cases_pvax','cases_fvax']]
df_date_start = df_states_cases.head(1)
df_date_end = df_states_cases.tail(1)
df_states_deaths = df_states_deaths[['date','state','deaths_new_dod','deaths_bid_dod','deaths_pvax','deaths_fvax']]
df_states_hosp = df_states_hosp[['date','state','admitted_covid','discharged_covid']]
df_states_vaksin = df_states_vaksin[['date','state','daily_partial','daily_full','daily_booster','daily']]
df_states_pop = df_states_pop[['state','pop']]
In [5]:
#Grouping and summation the detasets based on states columns
df_cases = df_states_cases.groupby('state').sum()
df_deaths = df_states_deaths.groupby('state').sum()
df_hosp = df_states_hosp.groupby('state').sum()
df_vaksin = df_states_vaksin.groupby('state').sum()
In [6]:
#Dataset for overall Malaysia Covid19
df_mas_cases = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_malaysia.csv')
df_mas_deaths = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_malaysia.csv')
df_mas_test = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/tests_malaysia.csv')
df_mas_vaksin = pd.read_csv('https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_malaysia.csv')
df_mas_pop = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/static/population.csv')
df_mas_aefi = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/vaccination/aefi.csv')
In [7]:
df_mas_vaksin['Total Pfizer'] = df_mas_vaksin['pfizer1'] + df_mas_vaksin['pfizer2']
df_mas_vaksin['Total Sinovac'] = df_mas_vaksin['sinovac1'] + df_mas_vaksin['sinovac2']
df_mas_vaksin['Total AstraZ'] = df_mas_vaksin['astra1'] + df_mas_vaksin['astra2']
df_mas_vaksin['Cum. Daily'] = df_mas_vaksin['daily_full'].cumsum()
df_mas_vaksin['Population'] = df_states_pop.at[df_states_pop.index[0],'pop']
df_mas_vaksin['Vax. (%)'] = (df_mas_vaksin['Cum. Daily']/df_mas_vaksin['Population'])*100
In [8]:
df_mas_cases = df_mas_cases[['date','cases_new','cases_recovered','cases_pvax','cases_fvax','cases_active']]
df_mas_deaths = df_mas_deaths[['date','deaths_new_dod','deaths_bid_dod','deaths_pvax','deaths_fvax']]
df_mas_vaksin = df_mas_vaksin[['date', 'daily_partial', 'daily_full', 'daily_booster', 'daily', 'Total Pfizer',
                               'Total Sinovac', 'Total AstraZ', 'cansino', 'Cum. Daily', 'Vax. (%)']]
In [9]:
df_mas = pd.merge(df_mas_cases, df_mas_deaths, on='date')
In [10]:
df_mas = pd.merge(df_mas, df_mas_vaksin, on='date')
In [11]:
#Merging the datasets into one datasets
df_states = pd.merge(df_cases,df_deaths,on='state')
In [12]:
df_states = pd.merge(df_states,df_hosp,on='state')
In [13]:
df_states = pd.merge(df_states,df_vaksin,on='state')
In [14]:
df_states = pd.merge(df_states,df_states_pop,on='state')
In [15]:
#Creating main tables for presentation
df_states_table = df_states
df_states_table['deaths_vax_total'] = df_states_table['deaths_pvax'] + df_states_table['deaths_fvax']
df_states_table['cases_vax_total'] = df_states_table['cases_pvax'] + df_states_table['cases_fvax']

df_states_table = df_states_table[['state','cases_new','cases_recovered','cases_vax_total','deaths_new_dod',
                                  'deaths_bid_dod','deaths_vax_total','daily_partial','daily_full','daily',
                                   'daily_booster','pop']]

df_states_table.loc['Total'] = df_states_table.sum(numeric_only=True, axis=0)
df_states_table['state'] = df_states_table['state'].replace(np.nan, 'Malaysia')

df_states_table['Cases (%)'] = df_states_table['cases_new']/df_states_table['pop']*100
df_states_table['Cases Recovered (%)'] = df_states_table['cases_recovered']/df_states_table['cases_new']*100
df_states_table['Cases Vax. (%)'] = df_states_table['cases_vax_total']/df_states_table['cases_new']*100
df_states_table['Deaths (%)'] = df_states_table['deaths_new_dod']/df_states_table['cases_new']*100
df_states_table['Deaths Vax. (%)'] = df_states_table['deaths_vax_total']/df_states_table['deaths_new_dod']*100
df_states_table['Deaths BID (%)'] = df_states_table['deaths_bid_dod']/df_states_table['deaths_new_dod']*100
df_states_table['Vax. 3D (%)'] = df_states_table['daily_booster']/df_states_table['pop']*100
df_states_table['Vax. 2D (%)'] = df_states_table['daily_full']/df_states_table['pop']*100
df_states_table['Vax. 1D (%)'] = df_states_table['daily_partial']/df_states_table['pop']*100

df_states_table.rename(columns={'state':'States','cases_new':'Cases Positive','cases_recovered':'Cases Recovered',
                               'cases_vax_total':'Cases Vax.','deaths_new_dod':'Death Cases',
                               'deaths_bid_dod':'Death BID','deaths_vax_total':'Deaths Vax.',
                               },inplace=True)#'daily':'Total Vaccinated','pop':'Population'
In [16]:
print('Report Start Date :', df_date_start.at[df_date_start.index[0],'date'])
print('Report End Date   :', df_date_end.at[df_date_end.index[0],'date'])
Report Start Date : 2020-01-25
Report End Date   : 2022-04-04
In [17]:
df_mas_cases['total_vax'] = df_mas_cases['cases_pvax'] + df_mas_cases['cases_fvax']
df_mas_cases['cum_new'] = df_mas_cases['cases_new'].cumsum()
df_mas_cases['cum_recovered'] = df_mas_cases['cases_recovered'].cumsum()
df_mas_cases['cum_vax'] = df_mas_cases['total_vax'].cumsum()
df_mas_cases['active_cum'] = df_mas_cases['cases_active'].cumsum()

df_mas_deaths['total_vax'] = df_mas_deaths['deaths_pvax'] + df_mas_deaths['deaths_fvax']
df_mas_deaths['cum_deaths'] = df_mas_deaths['deaths_new_dod'].cumsum()
df_mas_deaths['cum_vax'] = df_mas_deaths['total_vax'].cumsum()
In [18]:
df_mas_monthly = df_mas_cases.append(df_mas_deaths)

def getYearMonth(s):
  return s.split("-")[1]+"-"+s.split("-")[0]
df_mas_monthly['YearMonth']= df_mas_monthly['date'].apply(lambda x: getYearMonth(x))

df_mas_monthly = df_mas_monthly.groupby('YearMonth').sum()
df_mas_monthly = df_mas_monthly.reset_index()
df_mas_monthly['vax_total_cases'] = df_mas_monthly['cases_fvax']+df_mas_monthly['cases_pvax']
df_mas_monthly['vax_total_deaths'] = df_mas_monthly['deaths_fvax']+df_mas_monthly['deaths_pvax']
In [19]:
df_mas_yearly = df_mas_cases.append(df_mas_deaths)

def getYear(s):
  return s.split("-")[0]

def getMonth(s):
  return s.split("-")[1]

df_mas_yearly['Year']= df_mas_yearly['date'].apply(lambda x: getYear(x))
df_mas_yearly['Month']= df_mas_yearly['date'].apply(lambda x: getMonth(x))

df_mas_yearly = df_mas_yearly.groupby('Year').sum().reset_index()
df_mas_yearly['vax_total_cases'] = df_mas_yearly['cases_fvax']+df_mas_yearly['cases_pvax']
df_mas_yearly['vax_total_deaths'] = df_mas_yearly['deaths_fvax']+df_mas_yearly['deaths_pvax']
In [20]:
fig = make_subplots(rows=1, cols=2, shared_xaxes=True, vertical_spacing=0.08,
                   subplot_titles=('<b>Yearly Total Covid19 Cases & Recovered</b>',
                                   '<b>Monthly Total Covid19 Cases & Recovered</b>'))
#Graph 1
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['cases_new'],
                        name='Cases Positive',marker_color='red'),row=1, col=1)
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['cases_recovered'],
                        name='Cases Recovered',marker_color='blue'),row=1, col=1)
#Graph 2
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['cases_new'],
                        name='Cases Positive',marker_color='red'),row=1, col=2)
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['cases_recovered'],
                        name='Cases Recovered',marker_color='blue'),row=1, col=2)

#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False)
#fig.update_layout(height=400,showlegend=False,title_text='Yearly and Monthly Total New And Recovered Cases', title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [21]:
fig = make_subplots(rows=1, cols=2, shared_xaxes=True, vertical_spacing=0.08,
                   subplot_titles=('<b>Yearly Total Covid19 Death Cases</b>',
                                   '<b>Monthly Total Covid19 Death Cases</b>'))
#Graph 1
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['deaths_new_dod'],
                        name='Death Cases',marker_color='red'),row=1, col=1)
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['vax_total_deaths'],
                        name='Death Vax Cases',marker_color='blue'),row=1, col=1)

#Graph 2
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['deaths_new_dod'],
                        name='Death Cases',marker_color='red'),row=1, col=2)
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['vax_total_deaths'],
                        name='Death Vax Cases',marker_color='blue'),row=1, col=2)

#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False)
#fig.update_layout(height=400,showlegend=False,title_text='Yearly and Monthly Total New And Recovered Cases', title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [22]:
df_2020 = df_mas_cases.query("date >= '2020-01-01' \
                            and date <= '2020-12-31'")
df_2021 = df_mas_cases.query("date >= '2021-01-01' \
                            and date <= '2021-12-31'")
df_2022 = df_mas_cases.query("date >= '2022-01-01' \
                            and date <= '2022-12-31'")
In [23]:
df_2020['cum_2020'] = df_2020['cases_new'].cumsum()
df_2021['cum_2021'] = df_2021['cases_new'].cumsum()
df_2022['cum_2022'] = df_2022['cases_new'].cumsum()
In [24]:
death_2020 = df_mas_deaths.query("date >= '2020-01-01' \
                            and date <= '2020-12-31'")
death_2021 = df_mas_deaths.query("date >= '2021-01-01' \
                            and date <= '2021-12-31'")
death_2022 = df_mas_deaths.query("date >= '2022-01-01' \
                            and date <= '2022-12-31'")
In [25]:
death_2020['cum_2020'] = death_2020['deaths_new_dod'].cumsum()
death_2021['cum_2021'] = death_2021['deaths_new_dod'].cumsum()
death_2022['cum_2022'] = death_2022['deaths_new_dod'].cumsum()
In [26]:
fig = make_subplots(rows=1, cols=3, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}]],
                    
subplot_titles=('<b>Year 2020</b>',
                '<b>Year 2021</b>',
                '<b>Year 2022</b>'))

fig.add_trace(go.Scatter(x = df_2020['date'], y = df_2020['cases_new'], name = 'Daily Cases',
               line = dict(color='green', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_2020['date'], y = df_2020['cum_2020'], name = 'Cumulative Cases',
               line = dict(color='green', width=1.5)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_2020['date'], y = df_2020['cases_active'], name = 'Active Cases',
               line = dict(color='green', width=1.5)), secondary_y=True, row=1, col=1)

fig.add_trace(go.Scatter(x = df_2021['date'], y = df_2021['cases_new'], name = 'Cases Daily',
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=2)
fig.add_trace(go.Scatter(x = df_2021['date'], y = df_2021['cum_2021'], name = 'Cases',
               line = dict(color='blue', width=1.5)), secondary_y=True, row=1, col=2)
fig.add_trace(go.Scatter(x = df_2021['date'], y = df_2021['cases_active'], name = 'Active Cases',
               line = dict(color='blue', width=1.5)), secondary_y=True, row=1, col=2)

fig.add_trace(go.Scatter(x = df_2022['date'], y = df_2022['cases_new'], name = 'Daily Cases',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=3)
fig.add_trace(go.Scatter(x = df_2022['date'], y = df_2022['cum_2022'], name = 'Cumulative Cases',
               line = dict(color='red', width=1.5)), secondary_y=True, row=1, col=3)
fig.add_trace(go.Scatter(x = df_2022['date'], y = df_2022['cases_active'], name = 'Active Cases',
               line = dict(color='red', width=1.5)), secondary_y=True, row=1, col=3)

fig.update_layout(title_text='Malaysia Covid19 Cases By Year', title_x=0.5, showlegend=False,
                 height=350)
fig.update_xaxes(title_text='')
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=350,showlegend=False)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [27]:
fig = make_subplots(rows=1, cols=3, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}]],
                    
subplot_titles=('<b>Year 2020</b>',
                '<b>Year 2021</b>',
                '<b>Year 2022</b>'))

fig.add_trace(go.Scatter(x = death_2020['date'], y = death_2020['deaths_new_dod'], name = 'Daily Death Cases',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = death_2020['date'], y = death_2020['cum_2020'], name = 'Cumulative Death Cases',
               line = dict(color='blue', width=1.5)), secondary_y=True, row=1, col=1)

fig.add_trace(go.Scatter(x = death_2021['date'], y = death_2021['deaths_new_dod'], name = 'Daily Death Cases',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=2)
fig.add_trace(go.Scatter(x = death_2021['date'], y = death_2021['cum_2021'], name = 'Cumulative Death Cases',
               line = dict(color='blue', width=1.5)), secondary_y=True, row=1, col=2)

fig.add_trace(go.Scatter(x = death_2022['date'], y = death_2022['deaths_new_dod'], name = 'Daily Death Cases',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=3)
fig.add_trace(go.Scatter(x = death_2022['date'], y = death_2022['cum_2022'], name = 'Cumulative Death Cases',
               line = dict(color='blue', width=1.5)), secondary_y=True, row=1, col=3)


fig.update_layout(title_text='Malaysia Covid19 Death Cases By Year', title_x=0.5, showlegend=False,
                 height=350)
fig.update_xaxes(title_text='')
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=350,showlegend=False)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [28]:
df_mas_yearly_table = df_mas_yearly[['Year','cases_new','vax_total_cases','cases_recovered',
                                     'deaths_new_dod','vax_total_deaths']]

df_mas_yearly_table.rename(columns={'cases_new':'Cases Positive',
                                    'cases_recovered':'Cases Recovered',
                                    'vax_total_cases':'Cases Vax.',
                                    'deaths_new_dod':'Death Cases',
                                    'vax_total_deaths':'Deaths Vax.'},inplace=True)

df_mas_yearly_table.loc['Total'] = df_mas_yearly_table.sum(numeric_only=True, axis=0)
df_mas_yearly_table['Overall Cases (%)'] = (df_mas_yearly_table['Cases Positive']/df_mas_yearly_table['Cases Positive'].sum())*200
df_mas_yearly_table['Cases Vax. (%)'] = (df_mas_yearly_table['Cases Vax.']/df_mas_yearly_table['Cases Positive'])*100
df_mas_yearly_table['Recovered (%)'] = (df_mas_yearly_table['Cases Recovered']/df_mas_yearly_table['Cases Positive'])*100
df_mas_yearly_table['Death (%)'] = (df_mas_yearly_table['Death Cases']/df_mas_yearly_table['Cases Positive'])*100
df_mas_yearly_table['Deaths Vax. (%)'] = (df_mas_yearly_table['Deaths Vax.']/df_mas_yearly_table['Death Cases'])*100
df_mas_yearly_table['Year'] = df_mas_yearly_table['Year'].replace(np.nan, 'Total')

df_mas_yearly_table = df_mas_yearly_table[['Year','Cases Positive','Overall Cases (%)',
                                           'Cases Vax.','Cases Vax. (%)',
                                           'Cases Recovered','Recovered (%)',
                                           'Death Cases','Death (%)',
                                           'Deaths Vax.','Deaths Vax. (%)']]

df_mas_yearly_table.style.set_caption("Malaysia Covid19 Cases Yearly").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '20px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Cases Positive':'{:,.0f}','Cases Recovered':'{:,.0f}','Cases Vax.':'{:,.0f}',
     'Death Cases':'{:,.0f}','Deaths Vax.':'{:,.0f}','Recovered (%)':'{:,.1f}',
     'Death (%)':'{:,.1f}','Cases Vax. (%)':'{:,.1f}','Deaths Vax. (%)':'{:,.1f}',
     'Overall Cases (%)':'{:,.1f}'
    }).apply(lambda x: ['background: salmon' if x.name in ['Total'] else '' for i in x], axis=1).hide_index()
Out[28]:
Malaysia Covid19 Cases Yearly
Year Cases Positive Overall Cases (%) Cases Vax. Cases Vax. (%) Cases Recovered Recovered (%) Death Cases Death (%) Deaths Vax. Deaths Vax. (%)
2020 113,010 2.7 0 0.0 88,940 78.7 516 0.5 0 0.0
2021 2,645,076 62.1 1,059,319 40.0 2,596,438 98.2 31,062 1.2 10,799 34.8
2022 1,498,383 35.2 570,636 38.1 1,356,345 90.5 3,548 0.2 1,787 50.4
Total 4,256,469 100.0 1,629,955 38.3 4,041,723 95.0 35,126 0.8 12,586 35.8
In [29]:
df_q_cases = df_mas_cases
df_q_deaths = df_mas_deaths

df_q_cases = df_q_cases[['date','cases_new','total_vax','cases_recovered']]
df_q_cases.rename(columns={'cases_new':'Cases Positive','cases_recovered':'Cases Recovered',
                             'total_vax':'Cases Vax.'},inplace=True)

df_q_deaths = df_q_deaths[['date','deaths_new_dod','total_vax']]
df_q_deaths.rename(columns={'deaths_new_dod':'Death Cases',
                            'total_vax':'Deaths Vax.'},inplace=True)
In [30]:
q1_cases_2020 = df_q_cases.query("date >= '2020-01-01' \
                            and date <= '2020-03-31'")
q2_cases_2020 = df_q_cases.query("date >= '2020-04-01' \
                            and date <= '2020-06-30'")
q3_cases_2020 = df_q_cases.query("date >= '2020-07-01' \
                            and date <= '2020-09-30'")
q4_cases_2020 = df_q_cases.query("date >= '2020-10-01' \
                            and date <= '2020-12-31'")

q1_deaths_2020 = df_q_deaths.query("date >= '2020-01-01' \
                            and date <= '2020-03-31'")
q2_deaths_2020 = df_q_deaths.query("date >= '2020-04-01' \
                            and date <= '2020-06-30'")
q3_deaths_2020 = df_q_deaths.query("date >= '2020-07-01' \
                            and date <= '2020-09-30'")
q4_deaths_2020 = df_q_deaths.query("date >= '2020-10-01' \
                            and date <= '2020-12-31'")

def getYear(s):
  return s.split("-")[0]

q1_cases_2020['Year']= q1_cases_2020['date'].apply(lambda x: getYear(x))
q1_cases_2020 = q1_cases_2020.groupby('Year').sum().reset_index()
q1_cases_2020['Year'] = q1_cases_2020['Year'].replace('2020', 'Q1')

q2_cases_2020['Year']= q2_cases_2020['date'].apply(lambda x: getYear(x))
q2_cases_2020 = q2_cases_2020.groupby('Year').sum().reset_index()
q2_cases_2020['Year'] = q2_cases_2020['Year'].replace('2020', 'Q2')

q3_cases_2020['Year']= q3_cases_2020['date'].apply(lambda x: getYear(x))
q3_cases_2020 = q3_cases_2020.groupby('Year').sum().reset_index()
q3_cases_2020['Year'] = q3_cases_2020['Year'].replace('2020', 'Q3')

q4_cases_2020['Year']= q4_cases_2020['date'].apply(lambda x: getYear(x))
q4_cases_2020 = q4_cases_2020.groupby('Year').sum().reset_index()
q4_cases_2020['Year'] = q4_cases_2020['Year'].replace('2020', 'Q4')

q_cases_2020 = q1_cases_2020.append([q2_cases_2020,q3_cases_2020,q4_cases_2020])

q1_deaths_2020['Year']= q1_deaths_2020['date'].apply(lambda x: getYear(x))
q1_deaths_2020 = q1_deaths_2020.groupby('Year').sum().reset_index()
q1_deaths_2020['Year'] = q1_deaths_2020['Year'].replace('2020', 'Q1')

q2_deaths_2020['Year']= q2_deaths_2020['date'].apply(lambda x: getYear(x))
q2_deaths_2020 = q2_deaths_2020.groupby('Year').sum().reset_index()
q2_deaths_2020['Year'] = q2_deaths_2020['Year'].replace('2020', 'Q2')

q3_deaths_2020['Year']= q3_deaths_2020['date'].apply(lambda x: getYear(x))
q3_deaths_2020 = q3_deaths_2020.groupby('Year').sum().reset_index()
q3_deaths_2020['Year'] = q3_deaths_2020['Year'].replace('2020', 'Q3')

q4_deaths_2020['Year']= q4_deaths_2020['date'].apply(lambda x: getYear(x))
q4_deaths_2020 = q4_deaths_2020.groupby('Year').sum().reset_index()
q4_deaths_2020['Year'] = q4_deaths_2020['Year'].replace('2020', 'Q4')

q_deaths_2020 = q1_deaths_2020.append([q2_deaths_2020,q3_deaths_2020,q4_deaths_2020])

q_graph_2020 = pd.merge(q_cases_2020,q_deaths_2020,on='Year')
q_table_2020 = pd.merge(q_cases_2020,q_deaths_2020,on='Year')

q_table_2020.loc['Total'] = q_table_2020.sum(numeric_only=True, axis=0)
q_table_2020['Overall Cases (%)'] = (q_table_2020['Cases Positive']/q_table_2020['Cases Positive'].sum())*200
q_table_2020['Cases Vax. (%)'] = (q_table_2020['Cases Vax.']/q_table_2020['Cases Positive'])*100
q_table_2020['Recovered (%)'] = (q_table_2020['Cases Recovered']/q_table_2020['Cases Positive'])*100
q_table_2020['Death (%)'] = (q_table_2020['Death Cases']/q_table_2020['Cases Positive'])*100
q_table_2020['Deaths Vax. (%)'] = (q_table_2020['Deaths Vax.']/q_table_2020['Death Cases'])*100
q_table_2020['Year'] = q_table_2020['Year'].replace(np.nan, 'Total')

q_table_2020 = q_table_2020[['Year','Cases Positive','Overall Cases (%)',
                                           'Cases Vax.','Cases Vax. (%)',
                                           'Cases Recovered','Recovered (%)',
                                           'Death Cases','Death (%)',
                                           'Deaths Vax.','Deaths Vax. (%)']]

q_table_2020.style.set_caption("Malaysia Covid19 Quarterly Report Year 2020").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '20px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Cases Positive':'{:,.0f}','Cases Recovered':'{:,.0f}','Cases Vax.':'{:,.0f}',
     'Death Cases':'{:,.0f}','Deaths Vax.':'{:,.0f}','Recovered (%)':'{:,.1f}',
     'Death (%)':'{:,.1f}','Cases Vax. (%)':'{:,.1f}','Deaths Vax. (%)':'{:,.1f}',
     'Overall Cases (%)':'{:,.1f}'
    }).apply(lambda x: ['background: salmon' if x.name in ['Total'] else '' for i in x], axis=1).hide_index()
Out[30]:
Malaysia Covid19 Quarterly Report Year 2020
Year Cases Positive Overall Cases (%) Cases Vax. Cases Vax. (%) Cases Recovered Recovered (%) Death Cases Death (%) Deaths Vax. Deaths Vax. (%)
Q1 2,766 2.4 0 0.0 536 19.4 48 1.7 0 0.0
Q2 5,873 5.2 0 0.0 7,817 133.1 73 1.2 0 0.0
Q3 2,585 2.3 0 0.0 1,613 62.4 17 0.7 0 0.0
Q4 101,786 90.1 0 0.0 78,974 77.6 378 0.4 0 0.0
Total 113,010 100.0 0 0.0 88,940 78.7 516 0.5 0 0.0
In [31]:
q1_cases_2021 = df_q_cases.query("date >= '2021-01-01' \
                            and date <= '2021-03-31'")
q2_cases_2021 = df_q_cases.query("date >= '2021-04-01' \
                            and date <= '2021-06-30'")
q3_cases_2021 = df_q_cases.query("date >= '2021-07-01' \
                            and date <= '2021-09-30'")
q4_cases_2021 = df_q_cases.query("date >= '2021-10-01' \
                            and date <= '2021-12-31'")

q1_deaths_2021 = df_q_deaths.query("date >= '2021-01-01' \
                            and date <= '2021-03-31'")
q2_deaths_2021 = df_q_deaths.query("date >= '2021-04-01' \
                            and date <= '2021-06-30'")
q3_deaths_2021 = df_q_deaths.query("date >= '2021-07-01' \
                            and date <= '2021-09-30'")
q4_deaths_2021 = df_q_deaths.query("date >= '2021-10-01' \
                            and date <= '2021-12-31'")

def getYear(s):
  return s.split("-")[0]

q1_cases_2021['Year']= q1_cases_2021['date'].apply(lambda x: getYear(x))
q1_cases_2021 = q1_cases_2021.groupby('Year').sum().reset_index()
q1_cases_2021['Year'] = q1_cases_2021['Year'].replace('2021', 'Q1')

q2_cases_2021['Year']= q2_cases_2021['date'].apply(lambda x: getYear(x))
q2_cases_2021 = q2_cases_2021.groupby('Year').sum().reset_index()
q2_cases_2021['Year'] = q2_cases_2021['Year'].replace('2021', 'Q2')

q3_cases_2021['Year']= q3_cases_2021['date'].apply(lambda x: getYear(x))
q3_cases_2021 = q3_cases_2021.groupby('Year').sum().reset_index()
q3_cases_2021['Year'] = q3_cases_2021['Year'].replace('2021', 'Q3')

q4_cases_2021['Year']= q4_cases_2021['date'].apply(lambda x: getYear(x))
q4_cases_2021 = q4_cases_2021.groupby('Year').sum().reset_index()
q4_cases_2021['Year'] = q4_cases_2021['Year'].replace('2021', 'Q4')

q_cases_2021 = q1_cases_2021.append([q2_cases_2021,q3_cases_2021,q4_cases_2021])

q1_deaths_2021['Year']= q1_deaths_2021['date'].apply(lambda x: getYear(x))
q1_deaths_2021 = q1_deaths_2021.groupby('Year').sum().reset_index()
q1_deaths_2021['Year'] = q1_deaths_2021['Year'].replace('2021', 'Q1')

q2_deaths_2021['Year']= q2_deaths_2021['date'].apply(lambda x: getYear(x))
q2_deaths_2021 = q2_deaths_2021.groupby('Year').sum().reset_index()
q2_deaths_2021['Year'] = q2_deaths_2021['Year'].replace('2021', 'Q2')

q3_deaths_2021['Year']= q3_deaths_2021['date'].apply(lambda x: getYear(x))
q3_deaths_2021 = q3_deaths_2021.groupby('Year').sum().reset_index()
q3_deaths_2021['Year'] = q3_deaths_2021['Year'].replace('2021', 'Q3')

q4_deaths_2021['Year']= q4_deaths_2021['date'].apply(lambda x: getYear(x))
q4_deaths_2021 = q4_deaths_2021.groupby('Year').sum().reset_index()
q4_deaths_2021['Year'] = q4_deaths_2021['Year'].replace('2021', 'Q4')

q_deaths_2021 = q1_deaths_2021.append([q2_deaths_2021,q3_deaths_2021,q4_deaths_2021])

q_graph_2021 = pd.merge(q_cases_2021,q_deaths_2021,on='Year')
q_table_2021 = pd.merge(q_cases_2021,q_deaths_2021,on='Year')

q_table_2021.loc['Total'] = q_table_2021.sum(numeric_only=True, axis=0)
q_table_2021['Overall Cases (%)'] = (q_table_2021['Cases Positive']/q_table_2021['Cases Positive'].sum())*200
q_table_2021['Cases Vax. (%)'] = (q_table_2021['Cases Vax.']/q_table_2021['Cases Positive'])*100
q_table_2021['Recovered (%)'] = (q_table_2021['Cases Recovered']/q_table_2021['Cases Positive'])*100
q_table_2021['Death (%)'] = (q_table_2021['Death Cases']/q_table_2021['Cases Positive'])*100
q_table_2021['Deaths Vax. (%)'] = (q_table_2021['Deaths Vax.']/q_table_2021['Death Cases'])*100
q_table_2021['Year'] = q_table_2021['Year'].replace(np.nan, 'Total')

q_table_2021 = q_table_2021[['Year','Cases Positive','Overall Cases (%)',
                                           'Cases Vax.','Cases Vax. (%)',
                                           'Cases Recovered','Recovered (%)',
                                           'Death Cases','Death (%)',
                                           'Deaths Vax.','Deaths Vax. (%)']]

q_table_2021.style.set_caption("Malaysia Covid19 Quarterly Report Year 2021").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '20px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Cases Positive':'{:,.0f}','Cases Recovered':'{:,.0f}','Cases Vax.':'{:,.0f}',
     'Death Cases':'{:,.0f}','Deaths Vax.':'{:,.0f}','Recovered (%)':'{:,.1f}',
     'Death (%)':'{:,.1f}','Cases Vax. (%)':'{:,.1f}','Deaths Vax. (%)':'{:,.1f}',
     'Overall Cases (%)':'{:,.1f}'
    }).apply(lambda x: ['background: salmon' if x.name in ['Total'] else '' for i in x], axis=1).hide_index()
Out[31]:
Malaysia Covid19 Quarterly Report Year 2021
Year Cases Positive Overall Cases (%) Cases Vax. Cases Vax. (%) Cases Recovered Recovered (%) Death Cases Death (%) Deaths Vax. Deaths Vax. (%)
Q1 232,490 8.8 330 0.1 240,683 103.5 841 0.4 1 0.1
Q2 406,479 15.4 15,759 3.9 353,056 86.9 4,380 1.1 309 7.1
Q3 1,493,716 56.5 672,658 45.0 1,372,144 91.9 21,103 1.4 7,747 36.7
Q4 512,391 19.4 370,572 72.3 630,555 123.1 4,738 0.9 2,742 57.9
Total 2,645,076 100.0 1,059,319 40.0 2,596,438 98.2 31,062 1.2 10,799 34.8
In [32]:
q1_cases_2022 = df_q_cases.query("date >= '2022-01-01' \
                            and date <= '2022-03-31'")
q2_cases_2022 = df_q_cases.query("date >= '2022-04-01' \
                            and date <= '2022-06-30'")
q3_cases_2022 = df_q_cases.query("date >= '2022-07-01' \
                            and date <= '2022-09-30'")
q4_cases_2022 = df_q_cases.query("date >= '2022-10-01' \
                            and date <= '2022-12-31'")

q1_deaths_2022 = df_q_deaths.query("date >= '2022-01-01' \
                            and date <= '2022-03-31'")
q2_deaths_2022 = df_q_deaths.query("date >= '2022-04-01' \
                            and date <= '2022-06-30'")
q3_deaths_2022 = df_q_deaths.query("date >= '2022-07-01' \
                            and date <= '2022-09-30'")
q4_deaths_2022 = df_q_deaths.query("date >= '2022-10-01' \
                            and date <= '2022-12-31'")

def getYear(s):
  return s.split("-")[0]

q1_cases_2022['Year']= q1_cases_2022['date'].apply(lambda x: getYear(x))
q1_cases_2022 = q1_cases_2022.groupby('Year').sum().reset_index()
q1_cases_2022['Year'] = q1_cases_2022['Year'].replace('2022', 'Q1')

q2_cases_2022['Year']= q2_cases_2022['date'].apply(lambda x: getYear(x))
q2_cases_2022 = q2_cases_2022.groupby('Year').sum().reset_index()
q2_cases_2022['Year'] = q2_cases_2022['Year'].replace('2022', 'Q2')

q3_cases_2022['Year']= q3_cases_2022['date'].apply(lambda x: getYear(x))
q3_cases_2022 = q3_cases_2022.groupby('Year').sum().reset_index()
q3_cases_2022['Year'] = q3_cases_2022['Year'].replace('2022', 'Q3')

q4_cases_2022['Year']= q4_cases_2022['date'].apply(lambda x: getYear(x))
q4_cases_2022 = q4_cases_2022.groupby('Year').sum().reset_index()
q4_cases_2022['Year'] = q4_cases_2022['Year'].replace('2022', 'Q4')

q_cases_2022 = q1_cases_2022.append([q2_cases_2022,q3_cases_2022,q4_cases_2022])

q1_deaths_2022['Year']= q1_deaths_2022['date'].apply(lambda x: getYear(x))
q1_deaths_2022 = q1_deaths_2022.groupby('Year').sum().reset_index()
q1_deaths_2022['Year'] = q1_deaths_2022['Year'].replace('2022', 'Q1')

q2_deaths_2022['Year']= q2_deaths_2022['date'].apply(lambda x: getYear(x))
q2_deaths_2022 = q2_deaths_2022.groupby('Year').sum().reset_index()
q2_deaths_2022['Year'] = q2_deaths_2022['Year'].replace('2022', 'Q2')

q3_deaths_2022['Year']= q3_deaths_2022['date'].apply(lambda x: getYear(x))
q3_deaths_2022 = q3_deaths_2022.groupby('Year').sum().reset_index()
q3_deaths_2022['Year'] = q3_deaths_2022['Year'].replace('2022', 'Q3')

q4_deaths_2022['Year']= q4_deaths_2022['date'].apply(lambda x: getYear(x))
q4_deaths_2022 = q4_deaths_2022.groupby('Year').sum().reset_index()
q4_deaths_2022['Year'] = q4_deaths_2022['Year'].replace('2022', 'Q4')

q_deaths_2022 = q1_deaths_2022.append([q2_deaths_2022,q3_deaths_2022,q4_deaths_2022])

q_graph_2022 = pd.merge(q_cases_2022,q_deaths_2022,on='Year')
q_table_2022 = pd.merge(q_cases_2022,q_deaths_2022,on='Year')

q_table_2022.loc['Total'] = q_table_2022.sum(numeric_only=True, axis=0)
q_table_2022['Overall Cases (%)'] = (q_table_2022['Cases Positive']/q_table_2022['Cases Positive'].sum())*200
q_table_2022['Cases Vax. (%)'] = (q_table_2022['Cases Vax.']/q_table_2022['Cases Positive'])*100
q_table_2022['Recovered (%)'] = (q_table_2022['Cases Recovered']/q_table_2022['Cases Positive'])*100
q_table_2022['Death (%)'] = (q_table_2022['Death Cases']/q_table_2022['Cases Positive'])*100
q_table_2022['Deaths Vax. (%)'] = (q_table_2022['Deaths Vax.']/q_table_2022['Death Cases'])*100
q_table_2022['Year'] = q_table_2022['Year'].replace(np.nan, 'Total')

q_table_2022 = q_table_2022[['Year','Cases Positive','Overall Cases (%)',
                                           'Cases Vax.','Cases Vax. (%)',
                                           'Cases Recovered','Recovered (%)',
                                           'Death Cases','Death (%)',
                                           'Deaths Vax.','Deaths Vax. (%)']]

q_table_2022.style.set_caption("Malaysia Covid19 Quarterly Report Year 2022").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '20px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Cases Positive':'{:,.0f}','Cases Recovered':'{:,.0f}','Cases Vax.':'{:,.0f}',
     'Death Cases':'{:,.0f}','Deaths Vax.':'{:,.0f}','Recovered (%)':'{:,.1f}',
     'Death (%)':'{:,.1f}','Cases Vax. (%)':'{:,.1f}','Deaths Vax. (%)':'{:,.1f}',
     'Overall Cases (%)':'{:,.1f}'
    }).apply(lambda x: ['background: salmon' if x.name in ['Total'] else '' for i in x], axis=1).hide_index()
Out[32]:
Malaysia Covid19 Quarterly Report Year 2022
Year Cases Positive Overall Cases (%) Cases Vax. Cases Vax. (%) Cases Recovered Recovered (%) Death Cases Death (%) Deaths Vax. Deaths Vax. (%)
Q1 1,443,833 96.4 558,027 38.6 1,274,704 88.3 3,501 0.2 1,762 50.3
Q2 54,550 3.6 12,609 23.1 81,641 149.7 47 0.1 25 53.2
Total 1,498,383 100.0 570,636 38.1 1,356,345 90.5 3,548 0.2 1,787 50.4
In [33]:
fig = make_subplots(rows=1, cols=3, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}]],
                    
subplot_titles=('<b>Year 2020</b>',
                '<b>Year 2021</b>',
                '<b>Year 2022</b>'))
#Graph 1
fig.append_trace(go.Bar(x = q_graph_2020['Year'], y = q_graph_2020['Cases Positive'],
                        name='Cases Positive',marker_color='red'),row=1, col=1)
fig.append_trace(go.Bar(x = q_graph_2020['Year'], y = q_graph_2020['Cases Recovered'],
                        name='Cases Recovered',marker_color='blue'),row=1, col=1)
#Graph 2
fig.append_trace(go.Bar(x = q_graph_2021['Year'], y = q_graph_2021['Cases Positive'],
                        name='Cases Positive',marker_color='red'),row=1, col=2)
fig.append_trace(go.Bar(x = q_graph_2021['Year'], y = q_graph_2021['Cases Recovered'],
                        name='Cases Recovered',marker_color='blue'),row=1, col=2)
#Graph 3
fig.append_trace(go.Bar(x = q_graph_2022['Year'], y = q_graph_2022['Cases Positive'],
                        name='Cases Positive',marker_color='red'),row=1, col=3)
fig.append_trace(go.Bar(x = q_graph_2022['Year'], y = q_graph_2022['Cases Recovered'],
                        name='Cases Recovered',marker_color='blue'),row=1, col=3)

#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False)
fig.update_layout(height=400,showlegend=False,title_text='Covid19 Quarterly Report: Positive VS Recovered Cases', title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [34]:
fig = make_subplots(rows=1, cols=3, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}]],
                    
subplot_titles=('<b>Year 2020</b>',
                '<b>Year 2021</b>',
                '<b>Year 2022</b>'))
#Graph 1
fig.append_trace(go.Bar(x = q_graph_2020['Year'], y = q_graph_2020['Death Cases'],
                        name='Death Cases',marker_color='red'),row=1, col=1)
fig.append_trace(go.Bar(x = q_graph_2020['Year'], y = q_graph_2020['Deaths Vax.'],
                        name='Deaths Vax.',marker_color='blue'),row=1, col=1)
#Graph 2
fig.append_trace(go.Bar(x = q_graph_2021['Year'], y = q_graph_2021['Death Cases'],
                        name='Death Cases',marker_color='red'),row=1, col=2)
fig.append_trace(go.Bar(x = q_table_2021['Year'], y = q_graph_2021['Deaths Vax.'],
                        name='Deaths Vax.',marker_color='blue'),row=1, col=2)
#Graph 3
fig.append_trace(go.Bar(x = q_graph_2022['Year'], y = q_graph_2022['Death Cases'],
                        name='Death Cases',marker_color='red'),row=1, col=3)
fig.append_trace(go.Bar(x = q_graph_2022['Year'], y = q_graph_2022['Deaths Vax.'],
                        name='Deaths Vax.',marker_color='blue'),row=1, col=3)

#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False)
fig.update_layout(height=400,showlegend=False,title_text='Covid19 Quarterly Report: Deaths Cases New VS Vax.', title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [35]:
fig = make_subplots(shared_xaxes=True, specs=[[{'secondary_y': True}]])

#Graph 1
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_new'], name ='Positive Cases', 
               line = dict(color='blue', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_recovered'], name = 'Recovered Cases',
               line = dict(color='red', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['total_vax'], name = 'Vax. Cases',
               line = dict(color='green', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_new'], name ='Cumulative Cases', 
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_recovered'], name = 'Cumulative Recovered',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_vax'], name = 'Cumulative Vax.',
               line = dict(color='green', width=1)), secondary_y=False, row=1, col=1)

fig.update_layout(title_text='Malaysia Covid19 New And Recovered Cases', title_x=0.5, showlegend=False,
                 height=600)
fig.update_xaxes(title_text='')
fig.update_annotations(font=dict(family="Helvetica", size=12))
fig.update_layout(font=dict(family="Helvetica", size=14))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-10-11', x1='2021-10-11',  y0=0, y1=1000000)
#fig.add_annotation(text='90% Vax.', x='2021-10-11', y=1000000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2020-09-26', x1='2020-09-26',  y0=0, y1=500000)
#fig.add_annotation(text='PRN Sabah', x='2020-09-26', y=500000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-11-20', x1='2021-11-20',  y0=0, y1=500000)
#fig.add_annotation(text='PRN Melaka', x='2021-11-20', y=500000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-12-06', x1='2021-12-06',  y0=0, y1=400000)
#fig.add_annotation(text='PRN Sarawak', x='2021-12-06', y=400000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-01-12', x1='2021-01-12',  y0=0, y1=600000)
#fig.add_annotation(text='Darurat Mula', x='2021-01-12', y=600000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-08-01', x1='2021-08-01',  y0=0, y1=1100000)
#fig.add_annotation(text='Darurat Tamat', x='2021-08-01', y=1100000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
fig.show()
In [36]:
fig = make_subplots(shared_xaxes=True, specs=[[{'secondary_y': True}]])

#Graph 1
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_deaths['deaths_new_dod'], name ='Death Cases', 
               line = dict(color='blue', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_deaths['total_vax'], name = 'Vax Death Cases',
               line = dict(color='red', width=1)), secondary_y=True, row=1, col=1)

fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_deaths['cum_deaths'], name ='Cum. Death Cases', 
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_deaths['cum_vax'], name = 'Cum. Vax Death Recovered',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=1)


fig.update_layout(title_text='Malaysia Covid19 Death Cases: New VS Vax', title_x=0.5, showlegend=False,
                 height=600)
fig.update_xaxes(title_text='')
fig.update_annotations(font=dict(family="Helvetica", size=12))
fig.update_layout(font=dict(family="Helvetica", size=14))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.show()
In [37]:
new_cases = df_mas_cases.tail(1)
new_deaths = df_mas_deaths.tail(1)
In [ ]:
 
In [38]:
#Creating the main key points from the datasets
print('Key Points Highlights:-')
print('-----------------------------------------------------------------')
print('1. Total Positive Cases                  :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Positive']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases (%)']),'%')
print('2. New Positive Cases                    :','{0:,.0f}'.format(new_cases.at[new_cases.index[0],'cases_new']))
print('3. Total Positive Cases After Vaccinated :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Vax.']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases Vax. (%)']),'%')
print('4. Total Recovered Cases                 :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Recovered']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases Recovered (%)']),'%')
print('5. New Recovered Cases                   :','{0:,.0f}'.format(new_cases.at[new_cases.index[0],'cases_recovered']))
print('6. Total Death Cases                     :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Death Cases']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Deaths (%)']),'%')
print('7. New Death Cases                       :','{0:,.0f}'.format(new_deaths.at[new_deaths.index[0],'deaths_new_dod']))
print('8. Total Death Cases After Vaccinated    :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Deaths Vax.']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Deaths Vax. (%)']),'%')
print('9. Total 1 Dose Vaccinated               :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_partial']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 1D (%)']),'%')
print('10. Total 2 Dose Vaccinated              :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_full']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 2D (%)']),'%')
print('11. Total 3 Dose Vaccinated              :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_booster']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 3D (%)']),'%')
print('-----------------------------------------------------------------')
Key Points Highlights:-
-----------------------------------------------------------------
1. Total Positive Cases                  : 4,256,469 / 13.0 %
2. New Positive Cases                    : 10,002
3. Total Positive Cases After Vaccinated : 1,629,955 / 38.3 %
4. Total Recovered Cases                 : 4,041,723 / 95.0 %
5. New Recovered Cases                   : 23,302
6. Total Death Cases                     : 35,126 / 0.8 %
7. New Death Cases                       : 0
8. Total Death Cases After Vaccinated    : 12,586 / 35.8 %
9. Total 1 Dose Vaccinated               : 27,320,381 / 83.7 %
10. Total 2 Dose Vaccinated              : 25,832,699 / 79.1 %
11. Total 3 Dose Vaccinated              : 15,862,983 / 48.6 %
-----------------------------------------------------------------
In [39]:
df_states_table.drop(['daily_partial','daily_full','pop','daily','daily_booster'],axis='columns',inplace=True)
In [40]:
#df_states_table.drop(['Cases Vax.','Death BID','Deaths Vax.'],axis='columns',inplace=True)
df_states_table['Overall Cases (%)'] = (df_states_table['Cases Positive']/df_states_table['Cases Positive'].sum())*200
df_states_table = df_states_table[['States','Cases Positive','Overall Cases (%)',
                                   'Cases (%)','Cases Vax. (%)',
                                   'Cases Recovered','Cases Recovered (%)',
                                   'Death Cases','Deaths (%)',
                                   'Deaths Vax. (%)','Deaths BID (%)',
                                   'Vax. 3D (%)','Vax. 2D (%)','Vax. 1D (%)']]
df_states_table = df_states_table.sort_values('Cases Positive',ascending=False)
df_states_table.style.set_caption("Malaysia Details Of Covid19 Cases At Each States").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Cases Positive':'{:,.0f}','Cases Recovered':'{:,.0f}','Cases Vax.':'{:,.0f}',
     'Death Cases':'{:,.0f}','Deaths (%)':'{:,.1f}','Deaths BID':'{:,.0f}',
     'Deaths Vax.':'{:,.0f}','Cases (%)':'{:,.1f}','Cases Recovered (%)':'{:,.1f}',
     'Cases Vax. (%)':'{:,.1f}','Vax. 2D (%)':'{:,.1f}','Vax. 1D (%)':'{:,.1f}',
     'Deaths Vax. (%)':'{:,.1f}','Deaths BID (%)':'{:,.1f}','Vax. 3D (%)':'{:,.1f}',
     'Overall Cases (%)':'{:,.1f}'}
).set_properties(subset=['States'],**{'text-align': 'left'}).apply(
    lambda x: ['background: salmon' if x.name in ['Total'] else '' for i in x], axis=1).hide_index()
Out[40]:
Malaysia Details Of Covid19 Cases At Each States
States Cases Positive Overall Cases (%) Cases (%) Cases Vax. (%) Cases Recovered Cases Recovered (%) Death Cases Deaths (%) Deaths Vax. (%) Deaths BID (%) Vax. 3D (%) Vax. 2D (%) Vax. 1D (%)
Malaysia 4,256,469 100.0 13.0 38.3 4,041,723 95.0 35,126 0.8 35.8 21.1 48.6 79.1 83.7
Selangor 1,225,807 28.8 18.7 34.5 1,120,105 91.4 10,551 0.9 33.2 21.6 61.0 73.6 78.2
Johor 374,755 8.8 9.9 36.8 360,650 96.2 4,450 1.2 39.3 13.6 55.1 80.8 86.4
Sabah 368,220 8.7 9.6 41.1 352,460 95.7 3,113 0.8 25.6 40.7 23.4 62.9 63.4
W.P. Kuala Lumpur 331,594 7.8 19.0 31.7 314,550 94.9 2,803 0.8 34.7 25.9 97.9 174.3 184.1
Sarawak 300,264 7.1 10.6 48.6 291,755 97.2 1,695 0.6 48.4 21.6 55.1 76.0 85.0
Kedah 293,575 6.9 13.4 40.7 284,901 97.0 2,579 0.9 35.9 17.5 33.2 72.1 75.4
Pulau Pinang 269,880 6.3 15.2 41.0 264,176 97.9 1,953 0.7 40.3 21.5 59.8 86.4 90.9
Kelantan 245,657 5.8 12.7 46.4 241,865 98.5 1,415 0.6 35.9 27.8 16.7 61.4 63.5
Perak 191,693 4.5 7.6 38.7 182,932 95.4 1,856 1.0 44.9 15.2 45.5 74.5 78.6
Negeri Sembilan 191,608 4.5 17.0 31.0 182,047 95.0 1,460 0.8 30.5 12.5 57.6 84.6 89.5
Pahang 167,422 3.9 9.9 41.8 161,457 96.4 948 0.6 36.9 13.4 36.4 70.2 73.7
Terengganu 122,162 2.9 9.6 45.1 118,412 96.9 847 0.7 43.6 12.6 27.1 69.3 71.6
Melaka 117,708 2.8 12.6 35.9 112,291 95.4 1,093 0.9 37.7 14.2 57.2 76.8 82.4
W.P. Labuan 21,007 0.5 21.0 24.3 20,524 97.7 155 0.7 10.3 28.4 48.6 80.0 87.9
W.P. Putrajaya 18,273 0.4 15.7 40.2 17,402 95.2 32 0.2 40.6 3.1 70.2 127.4 138.1
Perlis 16,844 0.4 6.6 57.5 16,196 96.2 176 1.0 46.6 4.5 30.4 80.3 83.8
In [41]:
df_states_graph = df_states
df_states_graph['vaksin_percentage_partial'] = df_states_graph['daily_partial']/df_states_graph['pop']*100
df_states_graph['vaksin_percentage_full'] = df_states_graph['daily_full']/df_states_graph['pop']*100
df_states_graph['deaths_vax_total'] = df_states_graph['deaths_pvax'] + df_states_graph['deaths_fvax']
df_states_graph['cases_vax_total'] = df_states_graph['cases_pvax'] + df_states_graph['cases_fvax']
In [42]:
df_mas_deaths['deaths_vax_total'] = df_mas_deaths['deaths_pvax'] + df_mas_deaths['deaths_fvax']
df_mas['deaths_vax_total'] = df_mas['deaths_pvax'] + df_mas['deaths_fvax']
df_mas_test['total_test'] = df_mas_test['rtk-ag'] + df_mas_test['pcr']
df_mas_test['cum_total'] = df_mas_test['total_test'].cumsum()
In [43]:
df_mas_new = df_mas[['date','cases_new','deaths_new_dod']]
df_mas_new['cases_new_7'] = df_mas_new['cases_new'].shift(7)
df_mas_new['cases_new_14'] = df_mas_new['cases_new'].shift(14)
df_mas_new['cases_new_21'] = df_mas_new['cases_new'].shift(21)
df_mas_new['deaths_new_7'] = df_mas_new['deaths_new_dod'].shift(7)
df_mas_new['deaths_new_14'] = df_mas_new['deaths_new_dod'].shift(14)
df_mas_new['deaths_new_21'] = df_mas_new['deaths_new_dod'].shift(21)
df_mas_new = df_mas_new.tail(7)
df_mas_new['cum_new'] = df_mas_new['cases_new'].cumsum()
df_mas_new['cum_new_7'] = df_mas_new['cases_new_7'].cumsum()
df_mas_new['cum_new_14'] = df_mas_new['cases_new_14'].cumsum()
df_mas_new['cum_new_21'] = df_mas_new['cases_new_21'].cumsum()
df_mas_new['cum_deaths_new'] = df_mas_new['deaths_new_dod'].cumsum()
df_mas_new['cum_deaths_7'] = df_mas_new['deaths_new_7'].cumsum()
df_mas_new['cum_deaths_14'] = df_mas_new['deaths_new_14'].cumsum()
df_mas_new['cum_deaths_21'] = df_mas_new['deaths_new_21'].cumsum()
In [44]:
print('Four Weeks Cumulative Daily Cases Comparison Analysis:-')
print('--------------------------------------------')
print('Average Week 1: ', '{0:,.0f}'.format(df_mas_new['cum_new'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new'].mean()-df_mas_new['cum_new_7'].mean()),'diff.)')
print('Average Week 2: ', '{0:,.0f}'.format(df_mas_new['cum_new_7'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new_7'].mean()-df_mas_new['cum_new_14'].mean()),'diff.)')
print('Average Week 3: ', '{0:,.0f}'.format(df_mas_new['cum_new_14'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new_14'].mean()-df_mas_new['cum_new_21'].mean()),'diff.)')
print('Average Week 4: ', '{0:,.0f}'.format(df_mas_new['cum_new_21'].mean()), '-')
print('--------------------------------------------')
print('Four Weeks Daily Cases Comparison Analysis:-')
print('--------------------------------------------')
print('Average Week 1:', '{0:,.0f}'.format(df_mas_new['cases_new'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new'].mean()-df_mas_new['cases_new_7'].mean()),'diff.)')
print('Average Week 2:', '{0:,.0f}'.format(df_mas_new['cases_new_7'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new_7'].mean()-df_mas_new['cases_new_14'].mean()),'diff.)')
print('Average Week 3:', '{0:,.0f}'.format(df_mas_new['cases_new_14'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new_14'].mean()-df_mas_new['cases_new_21'].mean()),'diff.)')
print('Average Week 4:', '{0:,.0f}'.format(df_mas_new['cases_new_21'].mean()), '-')
print('--------------------------------------------')
Four Weeks Cumulative Daily Cases Comparison Analysis:-
--------------------------------------------
Average Week 1:  63,385 ( -22,914 diff.)
Average Week 2:  86,299 ( -15,211 diff.)
Average Week 3:  101,510 ( -17,474 diff.)
Average Week 4:  118,984 -
--------------------------------------------
Four Weeks Daily Cases Comparison Analysis:-
--------------------------------------------
Average Week 1: 14,895 ( -5,284 diff.)
Average Week 2: 20,179 ( -3,443 diff.)
Average Week 3: 23,622 ( -4,398 diff.)
Average Week 4: 28,020 -
--------------------------------------------
In [45]:
fig = make_subplots(rows=1, cols=4, shared_xaxes=True, vertical_spacing=0.08,
                   subplot_titles=('<b>New Confirmed Cases Daily</b>',
                                   '<b>New Confirmed Cases Cumulative</b>',
                                   '<b>New Deaths Cases Daily</b>',
                                   '<b>New Deaths Cases Cumulative</b>'))
#Graph 1
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new'],name='Week 1', mode="lines",
                           line = dict(color='red',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple',width=0.5)),row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=1)
#Graph 2
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new'],name='Week 1', mode="lines",
                           line = dict(color='red',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple',width=0.5)),row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="top left",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=2)
#Graph 3
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_dod'],name='Week 1', mode="lines",
                           line = dict(color='red', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple', width=0.5)),row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_dod'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=3)
#Graph 4
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_new'],name='Week 1', mode="lines",
                           line = dict(color='red', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_7'],name='Week 2', mode="lines",
                           line = dict(color='blue', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_14'],name='Week 3', mode="lines",
                           line = dict(color='green', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_21'],name='Week 4', mode="lines",
                           line = dict(color='purple', width=0.5)),row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="top right",row=1, col=4)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False,title_text="Malaysia Covid19 Latest Cases In Details (4 Week Comparison)", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black',
                visible=True, showticklabels=False)
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [46]:
df_mas_cases['cum_new'] = df_mas_cases['cases_new'].cumsum()
df_mas_cases['cum_recovered'] = df_mas_cases['cases_recovered'].cumsum()
df_mas_deaths['cum_deaths'] = df_mas_deaths['deaths_new_dod'].cumsum()
df_mas_deaths['cum_deaths_vax'] = df_mas_deaths['deaths_vax_total'].cumsum()
In [47]:
fig = make_subplots(rows=2, cols=4, shared_xaxes=True, vertical_spacing=0.08,
                    specs=[[{'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}], 
                           [{'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],

subplot_titles=('<b>Cases: Total VS Recover</b>',
                '<b>ICU Daily Admitted</b>',
                '<b>Hosp.: Admit VS Discharge</b>',
                '<b>PKRC: Admitted VS Discharged</b>',
                '<b>Deaths: Total, BID & Vax.</b>',
                '<b>Total Daily Covid19 Test</b>',
                '<b>States Hosp. Admission & Discharge</b>',
                '<b>States Vax. (%): 1D VS 2D</b>'))

#Graph 1
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_new'], name='Positive Cases',
                           line = dict(color='red',width=0.5)), row=1, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_new'], name='Positive Cases',
                           line = dict(color='red',width=1)), row=1, col=1, secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_recovered'],name='Recovered Cases',
                            line = dict(color='blue',width=0.5)),row=1, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_recovered'],name='Recovered Cases',
                            line = dict(color='blue',width=1)),row=1, col=1, secondary_y=False)
fig.add_hline(y=df_mas_cases['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Cases", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_cases['cases_recovered'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Recovered", annotation_position="top left",row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_icu_daily['date'], y = df_icu_daily['icu_covid'],name='ICU Covid',
                           line = dict(color='blue', width=0.5)),row=1, col=2, secondary_y=True)
fig.add_trace(go.Scatter(x = df_icu_daily['date'], y = df_icu_daily['icu_covid_cum'],name='ICU Covid',
                           line = dict(color='red', width=0.5)),row=1, col=2, secondary_y=False)
fig.add_hline(y = df_icu_daily['icu_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily", annotation_position="bottom left",row=1, col=2)
fig.add_hline(y = df_icu_daily['icu_covid_cum'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Cum.", annotation_position="bottom left",row=1, col=2)
# Graph 3
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_new_dod'],name='Deaths Cases',
                           line = dict(width=0.5, color='blue')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['cum_deaths'],name='Deaths Cases',
                           line = dict(width=1, color='blue')),row=2, col=1, secondary_y=False)
fig.add_hline(y=df_mas_deaths['deaths_new_dod'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily Deaths", annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_bid_dod'],name='BID Cases',
                           line = dict(width=0.5, color='red')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_vax_total'],name='Deaths Vaccinated Cases',
                            line = dict(width=0.5, color='black')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['cum_deaths_vax'],name='Deaths Vaccinated Cases',
                            line = dict(width=1, color='black')),row=2, col=1, secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mas_test['date'], y = df_mas_test['total_test'],name='Daily Covid19 Test',
                           line = dict(color='blue', width=0.5)),row=2, col=2, secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_test['date'], y = df_mas_test['cum_total'],name='Cumulative Covid19 Test',
                           line = dict(color='red', width=1)),row=2, col=2, secondary_y=True)
fig.add_hline(y=df_mas_test['total_test'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily Test", annotation_position="top left",row=2, col=2)
#Graph 5
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['admitted_covid'],name='Admitted',
                           line = dict(color='blue', width=0.5)),row=1, col=3, secondary_y=True)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['discharged_covid'],name='Discharged',
                           line = dict(color='red', width=0.5)),row=1, col=3, secondary_y=True)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['admitted_covid_cum'],name='Admitted',
                           line = dict(color='blue', width=1)),row=1, col=3, secondary_y=False)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['discharged_covid_cum'],name='Discharged',
                           line = dict(color='red', width=1)),row=1, col=3, secondary_y=False)
fig.add_hline(y = df_hosp_daily['admitted_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Admitted", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y = df_hosp_daily['discharged_covid'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Discharged", annotation_position="top left",row=1, col=3)
#Graph 6
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['admitted_covid'],name='Admitted',
                           line = dict(color='blue', width=0.5)),row=1, col=4, secondary_y=True)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['discharged_covid'],name='Discharged',
                           line = dict(color='red', width=0.5)),row=1, col=4, secondary_y=True)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['admitted_covid_cum'],name='Admitted',
                           line = dict(color='blue', width=1)),row=1, col=4, secondary_y=False)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['discharged_covid_cum'],name='Discharged',
                           line = dict(color='red', width=1)),row=1, col=4, secondary_y=False)
fig.add_hline(y = df_pkrc_daily['admitted_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Admitted", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y = df_pkrc_daily['discharged_covid'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Discharged", annotation_position="top left",row=1, col=4)
#Graph 7
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['admitted_covid'],name='Admitted Cases',
                       marker_color='blue'),row=2, col=3, secondary_y=False)
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['discharged_covid'],name='Discharged Cases',
                       marker_color='red'),row=2, col=3, secondary_y=False)
#Graph 8
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['vaksin_percentage_partial'],
                        name='Partial Vaksin (%)',marker_color='blue'),row=2, col=4, secondary_y=False)
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['vaksin_percentage_full'],
                        name='Full Vaksin (%)',marker_color='red'),row=2, col=4, secondary_y=False)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=600,showlegend=False,title_text="Malaysia Covid19 Cases Overview", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

# add a horizontal line & annotations
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0=0, x1=16, xref="paper", y0=90, y1=90, yref="y",row=2, col=4)
fig.add_annotation(text='90% Vax. Pop.', x=6, y=90, arrowhead=1, showarrow=True,row=2, col=4)
#Plotting the graph
fig.show()
In [48]:
fig = make_subplots(rows=1, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Total Daily Vax.</b>',
                '<b>Cumulative Daily Vax.</b>',
                '<b>Full, Partial & Booster</b>',
                '<b>Pfizer, Sinovac, AZ & Cansino</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily'],name='Total Daily Vaccinated',
                           line = dict(color='red',width=0.5)),row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Vax. (%)'],name='Vax. (%)',
                           line = dict(color='blue',width=0.5)),row=1, col=1,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Cum. Daily'],name='Cum. Daily Vaccinated',
                           line = dict(color='red',width=0.5)),row=1, col=2,secondary_y=False)
fig.add_hline(y=df_mas_vaksin['Cum. Daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Cum. Vax.", annotation_position="top left",row=1, col=2)
#Grpah 3
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_partial'],name='Partial',
                           line = dict(color='red',width=0.5)),row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_full'],name='Full',
                           line = dict(color='blue',width=0.5)),row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_booster'],name='Booster',
                           line = dict(color='green',width=0.5)),row=1, col=3,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=3)
#Graph 4
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total Pfizer'],name='Pfizer',
                           line = dict(color='red',width=0.5)),row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total Sinovac'],name='Sinovac',
                           line = dict(color='blue',width=0.5)),row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total AstraZ'],name='Astra Zaneca',
                           line = dict(color='green',width=0.5)),row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['cansino'],name='Cansino',
                           line = dict(color='black',width=0.5)),row=1, col=4,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=4)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=350,showlegend=False,title_text="Daily Vaccination Details", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [49]:
#Forecasting of New Cases VS Recovered Cases
#Importing the required module
#from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
#from statsmodels.tsa.statespace.varmax import VARMAX
#from statsmodels.tsa.api import VAR
#from statsmodels.tsa.stattools import grangercausalitytests, adfuller
#from tqdm import tqdm_notebook
#from itertools import product
#import statsmodels.api as sm
#import warnings
#warnings.filterwarnings('ignore')
#Importing the required datasets
#filepath_cases = 'https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_malaysia.csv'
#filepath_deaths = "https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_malaysia.csv"
#filepath_vaksin = 'https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_malaysia.csv'
#Preparing the required datasets
#filepath_cases = pd.read_csv(filepath_cases, parse_dates=['date'], index_col='date').astype('float64')
#filepath_deaths = pd.read_csv(filepath_deaths, parse_dates=['date'], index_col='date').astype('float64')
#filepath_vaksin = pd.read_csv(filepath_vaksin, parse_dates=['date'], index_col='date').astype('float64')
#macro_data = pd.merge(filepath_cases,filepath_deaths,on='date')
#macro_data = pd.merge(macro_data,filepath_vaksin,on='date')
#macro_data['cases_vax_total'] = macro_data['cases_pvax'] + macro_data['cases_fvax']
#macro_data['deaths_vax_total'] = macro_data['deaths_pvax'] + macro_data['deaths_fvax']
#macro_data = macro_data[['cases_new','cases_active']]
#train_df=macro_data[:-12]
#test_df=macro_data[-360:]
#model = VAR(train_df.diff()[1:])
#sorted_order=model.select_order(maxlags=30)
#var_model = VARMAX(train_df, order=(4,0),enforce_stationarity= False)
#fitted_model = var_model.fit(disp=True)
#Creating the required forecast
#n_forecast = 180
#predict = fitted_model.get_prediction(start=len(train_df),end=len(train_df) + n_forecast-1)
#predictions=predict.predicted_mean
#predictions.columns=['cases_predicted','cases_active_predicted']
#test_vs_pred=pd.concat([test_df,predictions],axis=1)
#test_vs_pred = test_vs_pred.reset_index()
#test_vs_pred['cases_new_cum'] = test_vs_pred['cases_new'].cumsum()
#test_vs_pred['cases_active_cum'] = test_vs_pred['cases_active'].cumsum()
#test_vs_pred['cases_predicted_cum'] = test_vs_pred['cases_predicted'].cumsum()
#test_vs_pred['cases_active_predicted_cum'] = test_vs_pred['cases_active_predicted'].cumsum()
#Plotting the required forecast
#fig = make_subplots(specs=[[{'secondary_y': True}]])
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_new'], name ='Positive Cases', line = dict(color='blue', width=1)), secondary_y=True)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_new_cum'], name ='Positive Cases', line = dict(color='blue', width=1)), secondary_y=False)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_active'], name = 'Positive Cases After Vaccinated',line = dict(color='red', width=1)), secondary_y=True)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_active_cum'], name = 'Positive Cases After Vaccinated',line = dict(color='red', width=1)), secondary_y=False)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_predicted'], name = 'Predicted Positive Cases',line = dict(color='blue', width=0.75)), secondary_y=True)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_active_predicted'], name = 'Predicted Positive Cases After Vaccinated',line = dict(color='red', width=0.75)), secondary_y=True)


#fig.update_layout(title_text='Malaysia Covid19 Forecast of Positive & Active Cases (Based on VAR Model)', title_x=0.5,showlegend=False, height=600)
#fig.update_xaxes(title_text='')
#fig.update_annotations(font=dict(family="Helvetica", size=12))
#fig.update_layout(font=dict(family="Helvetica", size=14))
#fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", x0='2021-10-11', x1='2021-10-11',  y0=0, y1=800000)
#fig.add_annotation(text='90% Adult Vax.', x='2021-10-11', y=800000, arrowhead=3, align='center', arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", x0='2021-11-20', x1='2021-11-20',  y0=0, y1=600000)
#fig.add_annotation(text='PRN Melaka', x='2021-11-20', y=600000, arrowhead=3, align='center', arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", x0='2021-12-06', x1='2021-12-06',  y0=0, y1=500000)
#fig.add_annotation(text='PRN Sarawak', x='2021-12-06', y=500000, arrowhead=3, align='center', arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, xanchor="left", yanchor="bottom")
#fig.show()
In [50]:
df = df_states_cases
df_joh = df[df.state == 'Johor']
df_ked = df[df.state == 'Kedah']
df_kel = df[df.state == 'Kelantan']
df_mel = df[df.state == 'Melaka']
df_neg = df[df.state == 'Negeri Sembilan']
df_pah = df[df.state == 'Pahang']
df_prk = df[df.state == 'Perak']
df_per = df[df.state == 'Perlis']
df_pen = df[df.state == 'Pulau Pinang']
df_sab = df[df.state == 'Sabah']
df_sar = df[df.state == 'Sarawak']
df_sel = df[df.state == 'Selangor']
df_ter = df[df.state == 'Terengganu']
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_lab = df[df.state == 'W.P. Labuan']
df_put = df[df.state == 'W.P. Putrajaya']
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_hline(y=df_joh['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=1)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_hline(y=df_ked['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=2)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_hline(y=df_kel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=3)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_hline(y=df_mel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=4)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_hline(y=df_neg['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_hline(y=df_pah['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=2)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_hline(y=df_prk['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=3)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_hline(y=df_per['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=4)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_hline(y=df_pen['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=1)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_hline(y=df_sab['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=2)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_hline(y=df_sar['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=3)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_hline(y=df_sel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=4)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_hline(y=df_ter['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=1)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_hline(y=df_kul['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=2)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_hline(y=df_lab['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=3)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_hline(y=df_put['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=4)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Cases & Recovered At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [51]:
df = df_states_deaths
df['deaths_vax_total'] = df['deaths_fvax'] + df['deaths_pvax'] 
df_joh = df[df.state == 'Johor']
df_ked = df[df.state == 'Kedah']
df_kel = df[df.state == 'Kelantan']
df_mel = df[df.state == 'Melaka']
df_neg = df[df.state == 'Negeri Sembilan']
df_pah = df[df.state == 'Pahang']
df_prk = df[df.state == 'Perak']
df_per = df[df.state == 'Perlis']
df_pen = df[df.state == 'Pulau Pinang']
df_sab = df[df.state == 'Sabah']
df_sar = df[df.state == 'Sarawak']
df_sel = df[df.state == 'Selangor']
df_ter = df[df.state == 'Terengganu']
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_lab = df[df.state == 'W.P. Labuan']
df_put = df[df.state == 'W.P. Putrajaya']
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_hline(y=df_joh['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=1)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=False)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_hline(y=df_ked['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=2)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=False)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_hline(y=df_kel['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=3)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_hline(y=df_mel['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=4)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=False)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_hline(y=df_neg['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=False)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_hline(y=df_pah['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=2)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=False)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_hline(y=df_prk['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=3)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=False)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_hline(y=df_per['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=4)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=False)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_hline(y=df_pen['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=1)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=False)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_hline(y=df_sab['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=2)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=False)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_hline(y=df_sar['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=3)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=False)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_hline(y=df_sel['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=4)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=False)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_hline(y=df_ter['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=1)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=False)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_hline(y=df_kul['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=2)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=False)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_hline(y=df_lab['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=3)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=False)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_hline(y=df_put['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=4)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=False)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Daily Deaths Total & Vaccinated At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [52]:
#Extracting And Separating Data For Each States
#Johor
df = df_states_vaksin
df_joh = df[df.state == 'Johor']
df_joh['cum_partial'] = df_joh['daily_partial'].cumsum()
df_joh['cum_full'] = df_joh['daily_full'].cumsum()
df_joh['cum_booster'] = df_joh['daily_booster'].cumsum()
#Kedah
df_ked = df[df.state == 'Kedah']
df_ked['cum_partial'] = df_ked['daily_partial'].cumsum()
df_ked['cum_full'] = df_ked['daily_full'].cumsum()
df_ked['cum_booster'] = df_ked['daily_booster'].cumsum()
#Kelantan
df_kel = df[df.state == 'Kelantan']
df_kel['cum_partial'] = df_kel['daily_partial'].cumsum()
df_kel['cum_full'] = df_kel['daily_full'].cumsum()
df_kel['cum_booster'] = df_kel['daily_booster'].cumsum()
#Melaka
df_mel = df[df.state == 'Melaka']
df_mel['cum_partial'] = df_mel['daily_partial'].cumsum()
df_mel['cum_full'] = df_mel['daily_full'].cumsum()
df_mel['cum_booster'] = df_mel['daily_booster'].cumsum()
#Negeri Sembilan
df_neg = df[df.state == 'Negeri Sembilan']
df_neg['cum_partial'] = df_neg['daily_partial'].cumsum()
df_neg['cum_full'] = df_neg['daily_full'].cumsum()
df_neg['cum_booster'] = df_neg['daily_booster'].cumsum()
#Pahang
df_pah = df[df.state == 'Pahang']
df_pah['cum_partial'] = df_pah['daily_partial'].cumsum()
df_pah['cum_full'] = df_pah['daily_full'].cumsum()
df_pah['cum_booster'] = df_pah['daily_booster'].cumsum()
#Perak
df_prk = df[df.state == 'Perak']
df_prk['cum_partial'] = df_prk['daily_partial'].cumsum()
df_prk['cum_full'] = df_prk['daily_full'].cumsum()
df_prk['cum_booster'] = df_prk['daily_booster'].cumsum()
#Perlis
df_per = df[df.state == 'Perlis']
df_per['cum_partial'] = df_per['daily_partial'].cumsum()
df_per['cum_full'] = df_per['daily_full'].cumsum()
df_per['cum_booster'] = df_per['daily_booster'].cumsum()
#Pulau Pinang
df_pen = df[df.state == 'Pulau Pinang']
df_pen['cum_partial'] = df_pen['daily_partial'].cumsum()
df_pen['cum_full'] = df_pen['daily_full'].cumsum()
df_pen['cum_booster'] = df_pen['daily_booster'].cumsum()
#Sabah
df_sab = df[df.state == 'Sabah']
df_sab['cum_partial'] = df_sab['daily_partial'].cumsum()
df_sab['cum_full'] = df_sab['daily_full'].cumsum()
df_sab['cum_booster'] = df_sab['daily_booster'].cumsum()
#Sarawak
df_sar = df[df.state == 'Sarawak']
df_sar['cum_partial'] = df_sar['daily_partial'].cumsum()
df_sar['cum_full'] = df_sar['daily_full'].cumsum()
df_sar['cum_booster'] = df_sar['daily_booster'].cumsum()
#Selangor
df_sel = df[df.state == 'Selangor']
df_sel['cum_partial'] = df_sel['daily_partial'].cumsum()
df_sel['cum_full'] = df_sel['daily_full'].cumsum()
df_sel['cum_booster'] = df_sel['daily_booster'].cumsum()
#Terengganu
df_ter = df[df.state == 'Terengganu']
df_ter['cum_partial'] = df_ter['daily_partial'].cumsum()
df_ter['cum_full'] = df_ter['daily_full'].cumsum()
df_ter['cum_booster'] = df_ter['daily_booster'].cumsum()
#Kuala Lumpur
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_kul['cum_partial'] = df_kul['daily_partial'].cumsum()
df_kul['cum_full'] = df_kul['daily_full'].cumsum()
df_kul['cum_booster'] = df_kul['daily_booster'].cumsum()
#Labuan
df_lab = df[df.state == 'W.P. Labuan']
df_lab['cum_partial'] = df_lab['daily_partial'].cumsum()
df_lab['cum_full'] = df_lab['daily_full'].cumsum()
df_lab['cum_booster'] = df_lab['daily_booster'].cumsum()
#Putrajaya
df_put = df[df.state == 'W.P. Putrajaya']
df_put['cum_partial'] = df_put['daily_partial'].cumsum()
df_put['cum_full'] = df_put['daily_full'].cumsum()
df_put['cum_booster'] = df_put['daily_booster'].cumsum()
In [53]:
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=1,secondary_y=False)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=2,secondary_y=False)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=3,secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=4,secondary_y=False)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=1,secondary_y=False)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=2,secondary_y=False)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=3,secondary_y=False)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=4,secondary_y=False)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=1,secondary_y=False)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=2,secondary_y=False)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=3,secondary_y=False)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=4,secondary_y=False)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=1,secondary_y=False)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=2,secondary_y=False)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=3,secondary_y=False)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=4,secondary_y=False)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Daily Vaccination (1D, 2D & 3D) At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [54]:
dfpop = df_states_pop
#Creating new vax percentage columns at each states
#Johor
df_joh_pop = dfpop[dfpop.state == 'Johor']
df_joh_pop = df_joh_pop.at[df_joh_pop.index[0],'pop']
df_joh['2 Dos (%)'] = (df_joh['cum_full']/df_joh_pop)*100
#Kedah
df_ked_pop = dfpop[dfpop.state == 'Kedah']
df_ked_pop = df_ked_pop.at[df_ked_pop.index[0],'pop']
df_ked['2 Dos (%)'] = (df_ked['cum_full']/df_ked_pop)*100
#Kelantan
df_kel_pop = dfpop[dfpop.state == 'Kelantan']
df_kel_pop = df_kel_pop.at[df_kel_pop.index[0],'pop']
df_kel['2 Dos (%)'] = (df_kel['cum_full']/df_kel_pop)*100
#Melaka
df_mel_pop = dfpop[dfpop.state == 'Melaka']
df_mel_pop = df_mel_pop.at[df_mel_pop.index[0],'pop']
df_mel['2 Dos (%)'] = (df_mel['cum_full']/df_mel_pop)*100
#Negeri Sembilan
df_neg_pop = dfpop[dfpop.state == 'Negeri Sembilan']
df_neg_pop = df_neg_pop.at[df_neg_pop.index[0],'pop']
df_neg['2 Dos (%)'] = (df_neg['cum_full']/df_neg_pop)*100
#Pahang
df_pah_pop = dfpop[dfpop.state == 'Pahang']
df_pah_pop = df_pah_pop.at[df_pah_pop.index[0],'pop']
df_pah['2 Dos (%)'] = (df_pah['cum_full']/df_pah_pop)*100
#Perak
df_prk_pop = dfpop[dfpop.state == 'Perak']
df_prk_pop = df_prk_pop.at[df_prk_pop.index[0],'pop']
df_prk['2 Dos (%)'] = (df_prk['cum_full']/df_prk_pop)*100
#Perlis
df_per_pop = dfpop[dfpop.state == 'Perlis']
df_per_pop = df_per_pop.at[df_per_pop.index[0],'pop']
df_per['2 Dos (%)'] = (df_per['cum_full']/df_per_pop)*100
#Penang
df_pen_pop = dfpop[dfpop.state == 'Pulau Pinang']
df_pen_pop = df_pen_pop.at[df_pen_pop.index[0],'pop']
df_pen['2 Dos (%)'] = (df_pen['cum_full']/df_pen_pop)*100
#Sabah
df_sab_pop = dfpop[dfpop.state == 'Sabah']
df_sab_pop = df_sab_pop.at[df_sab_pop.index[0],'pop']
df_sab['2 Dos (%)'] = (df_sab['cum_full']/df_sab_pop)*100
#Sarawak
df_sar_pop = dfpop[dfpop.state == 'Sarawak']
df_sar_pop = df_sar_pop.at[df_sar_pop.index[0],'pop']
df_sar['2 Dos (%)'] = (df_sar['cum_full']/df_sar_pop)*100
#Selangor
df_sel_pop = dfpop[dfpop.state == 'Selangor']
df_sel_pop = df_sel_pop.at[df_sel_pop.index[0],'pop']
df_sel['2 Dos (%)'] = (df_sel['cum_full']/df_sel_pop)*100
#Terengganu
df_ter_pop = dfpop[dfpop.state == 'Terengganu']
df_ter_pop = df_ter_pop.at[df_ter_pop.index[0],'pop']
df_ter['2 Dos (%)'] = (df_ter['cum_full']/df_ter_pop)*100
#Kuala Lumpur
df_kul_pop = dfpop[dfpop.state == 'W.P. Kuala Lumpur']
df_kul_pop = df_kul_pop.at[df_kul_pop.index[0],'pop']
df_kul['2 Dos (%)'] = (df_kul['cum_full']/df_kul_pop)*100
#Labuan
df_lab_pop = dfpop[dfpop.state == 'W.P. Labuan']
df_lab_pop = df_lab_pop.at[df_lab_pop.index[0],'pop']
df_lab['2 Dos (%)'] = (df_lab['cum_full']/df_lab_pop)*100
#Putrajaya
df_put_pop = dfpop[dfpop.state == 'W.P. Putrajaya']
df_put_pop = df_put_pop.at[df_put_pop.index[0],'pop']
df_put['2 Dos (%)'] = (df_put['cum_full']/df_put_pop)*100
#Start creating the graph
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=2)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=3)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=4)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=1)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=2)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=3)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=4)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=1)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=2)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=3)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=4)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=1)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=2)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=3)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=4)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,
                  title_text="Covid19 Vaccination Against Vaccination Per Population At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [55]:
#Retrieving dataset for Covid19 for all countries
dfworld = pd.read_csv('https://raw.githubusercontent.com/datasets/covid-19/main/data/time-series-19-covid-combined.csv')
dfworld['daily_cases'] = dfworld['Confirmed'].diff()
dfworld['daily_recover'] = dfworld['Recovered'].diff()
dfworld['daily_deaths'] = dfworld['Deaths'].diff()
In [56]:
dfworld2 = pd.read_csv('https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/latest/owid-covid-latest.csv')
dfworld2 = dfworld2[dfworld2['continent'].notna()] 
dfworld2 = dfworld2[['location','total_cases','total_deaths','people_vaccinated',
                     'population','population_density','gdp_per_capita']]
dfworld2['Cases (%)'] = (dfworld2['total_cases']/dfworld2['population'])*100
dfworld2['Deaths (%)'] = (dfworld2['total_deaths']/dfworld2['total_cases'])*100
dfworld2['Vaccination (%)'] = (dfworld2['people_vaccinated']/dfworld2['population'])*100

dfworld2.rename(columns={'location':'Country','total_cases':'Total Cases','total_deaths':'Total Deaths',
                         'people_vaccinated':'People Vaccinated','population':'Population',
                         'population_density':'Population Density','gdp_per_capita':'GDP Per Kapita'},inplace=True)
In [57]:
df_asean = dfworld2.loc[dfworld2['Country'].isin(['Malaysia','Singapore','Thailand','Indonesia',
                                              'Philippines','Cambodia','Laos','Vietnam',
                                              'Myanmar','Brunei'])]
df_asean = df_asean.sort_values('Total Cases',ascending=False)
def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

df_asean.style.set_caption("Overview Of Covid19 Cases In ASEAN Countries").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[57]:
Overview Of Covid19 Cases In ASEAN Countries
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
Vietnam 9,818,328 42,600 79,947,189 98,168,829 308.1 6,171.9 10.0 0.4 81.4
Indonesia 6,015,748 155,164 196,534,266 276,361,788 145.7 11,188.7 2.2 2.6 71.1
Malaysia 4,246,467 35,099 27,528,911 32,776,195 96.3 26,808.2 13.0 0.8 84.0
Thailand 3,736,487 25,512 55,585,303 69,950,844 135.1 16,277.7 5.3 0.7 79.5
Philippines 3,679,629 59,343 nan 111,046,910 351.9 7,599.2 3.3 1.6 nan
Singapore 1,109,744 1,276 5,005,722 5,453,600 7,915.7 85,535.4 20.3 0.1 91.8
Myanmar 611,875 19,433 27,030,964 54,806,014 81.7 5,591.6 1.1 3.2 49.3
Laos 183,560 679 5,605,948 7,379,358 29.7 6,397.4 2.5 0.4 76.0
Brunei 135,974 213 nan 441,532 81.3 71,809.3 30.8 0.2 nan
Cambodia 135,747 3,054 14,829,078 16,946,446 90.7 3,645.1 0.8 2.2 87.5
In [58]:
#Selecting datasets for ASEAN Countries
#Malaysia
dfworld.rename(columns={'Country/Region':'Country'},inplace=True)
df_mas = dfworld[dfworld.Country == 'Malaysia']
df_mas = df_mas.reset_index(drop=True)
df_mas = df_mas.drop([0])
#Indonesia
df_ind = dfworld[dfworld.Country == 'Indonesia']
df_ind = df_ind.reset_index(drop=True)
df_ind = df_ind.drop([0])
#Philippines
df_phi = dfworld[dfworld.Country == 'Philippines']
df_phi = df_phi.reset_index(drop=True)
df_phi = df_phi.drop([0])
#Burma
df_bur = dfworld[dfworld.Country == 'Burma']
df_bur = df_bur.reset_index(drop=True)
df_bur = df_bur.drop([0])
#Singapore
df_sin = dfworld[dfworld.Country == 'Singapore']
df_sin = df_sin.reset_index(drop=True)
df_sin = df_sin.drop([0])
#Thailand
df_tha = dfworld[dfworld.Country == 'Thailand']
df_tha = df_tha.reset_index(drop=True)
df_tha = df_tha.drop([0])
#Vietnam
df_vie = dfworld[dfworld.Country == 'Vietnam']
df_vie = df_vie.reset_index(drop=True)
df_vie = df_vie.drop([0])
#Cambodia
df_cam = dfworld[dfworld.Country == 'Cambodia']
df_cam = df_cam.reset_index(drop=True)
df_cam = df_cam.drop([0])
#Brunei
df_bru = dfworld[dfworld.Country == 'Brunei']
df_bru = df_bru.reset_index(drop=True)
df_bru = df_bru.drop([0])
#Laos
df_lao = dfworld[dfworld.Country == 'Laos']
df_lao = df_lao.reset_index(drop=True)
df_lao = df_lao.drop([0])
In [59]:
#Creating the ASEAN Covid19 Cases Graphs
fig = make_subplots(rows=2, cols=5, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Malaysia</b>', '<b>Indonesia</b>', '<b>Philippines</b>', '<b>Burma</b>', '<b>Singapore</b>',
                '<b>Thailand</b>', '<b>Vietnam</b>', '<b>Cambodia</b>', '<b>Brunei</b>', '<b>Laos</b>'))
#Row 1
#Graph 1
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=5,secondary_y=True)
#Row 2
#Graph 6
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=5,secondary_y=True)

#Adding title and adjusting the layout
fig.update_layout(height=500,showlegend=False,title_text="Covid19 Total And Daily Cases At ASEAN Countries",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [60]:
#Creating the ASEAN Covid19 Cases Graphs
fig = make_subplots(rows=2, cols=5, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Malaysia</b>', '<b>Indonesia</b>', '<b>Philippines</b>', '<b>Burma</b>', '<b>Singapore</b>',
                '<b>Thailand</b>', '<b>Vietnam</b>', '<b>Cambodia</b>', '<b>Brunei</b>', '<b>Laos</b>'))
#Row 1
#Graph 1
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=5,secondary_y=True)
#Row 2
#Graph 6
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=5,secondary_y=True)

#Adding title and adjusting the layout
fig.update_layout(height=500,showlegend=False,title_text="Covid19 Total Deaths And Daily Cases At ASEAN Countries",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [61]:
dfworld3 = dfworld2.sort_values('Total Cases',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Covid19 Cases Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[61]:
Overview Of Top 10 Highest Covid19 Cases Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
United States 80,155,397 982,565 255,713,962 332,915,074 35.6 54,225.4 24.1 1.2 76.8
India 43,029,044 521,358 989,520,028 1,393,409,033 450.4 6,426.7 3.1 1.2 71.0
Brazil 30,002,785 660,410 181,342,972 213,993,441 25.0 14,103.5 14.0 2.2 84.7
France 26,051,185 142,575 54,000,794 67,422,000 122.6 38,605.7 38.6 0.5 80.1
Germany 21,706,329 130,052 63,685,575 83,900,471 237.0 45,229.2 25.9 0.6 75.9
United Kingdom 21,285,727 165,721 52,803,065 68,207,114 272.9 39,753.2 31.2 0.8 77.4
Russia 17,636,019 362,304 79,968,434 145,912,022 8.8 24,766.0 12.1 2.1 54.8
Turkey 14,894,731 98,157 57,785,259 85,042,736 104.9 25,129.3 17.5 0.7 67.9
Italy 14,845,815 159,784 50,731,160 60,367,471 205.9 35,220.1 24.6 1.1 84.0
South Korea 14,001,406 17,453 44,974,446 51,305,184 528.0 35,938.4 27.3 0.1 87.7
In [62]:
dfworld3 = dfworld2.sort_values('People Vaccinated',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Covid19 People Vaccinated Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[62]:
Overview Of Top 10 Highest Covid19 People Vaccinated Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
China 259,389 4,638 1,275,541,000 1,444,216,102 147.7 15,308.7 0.0 1.8 88.3
India 43,029,044 521,358 989,520,028 1,393,409,033 450.4 6,426.7 3.1 1.2 71.0
United States 80,155,397 982,565 255,713,962 332,915,074 35.6 54,225.4 24.1 1.2 76.8
Indonesia 6,015,748 155,164 196,534,266 276,361,788 145.7 11,188.7 2.2 2.6 71.1
Brazil 30,002,785 660,410 181,342,972 213,993,441 25.0 14,103.5 14.0 2.2 84.7
Pakistan 1,525,620 30,361 132,208,776 225,199,929 255.6 5,034.7 0.7 2.0 58.7
Bangladesh 1,951,770 29,122 128,218,843 166,303,494 1,265.0 3,524.0 1.2 1.5 77.1
Japan 6,700,637 28,287 102,621,870 126,050,796 347.8 39,002.2 5.3 0.4 81.4
Mexico 5,666,215 323,223 85,580,293 130,262,220 66.4 17,336.5 4.3 5.7 65.7
Russia 17,636,019 362,304 79,968,434 145,912,022 8.8 24,766.0 12.1 2.1 54.8
In [63]:
dfworld3 = dfworld2.sort_values('Population',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Population Countries Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[63]:
Overview Of Top 10 Highest Population Countries Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
China 259,389 4,638 1,275,541,000 1,444,216,102 147.7 15,308.7 0.0 1.8 88.3
India 43,029,044 521,358 989,520,028 1,393,409,033 450.4 6,426.7 3.1 1.2 71.0
United States 80,155,397 982,565 255,713,962 332,915,074 35.6 54,225.4 24.1 1.2 76.8
Indonesia 6,015,748 155,164 196,534,266 276,361,788 145.7 11,188.7 2.2 2.6 71.1
Pakistan 1,525,620 30,361 132,208,776 225,199,929 255.6 5,034.7 0.7 2.0 58.7
Brazil 30,002,785 660,410 181,342,972 213,993,441 25.0 14,103.5 14.0 2.2 84.7
Nigeria 255,468 3,142 21,049,754 211,400,704 209.6 5,338.5 0.1 1.2 10.0
Bangladesh 1,951,770 29,122 128,218,843 166,303,494 1,265.0 3,524.0 1.2 1.5 77.1
Russia 17,636,019 362,304 79,968,434 145,912,022 8.8 24,766.0 12.1 2.1 54.8
Mexico 5,666,215 323,223 85,580,293 130,262,220 66.4 17,336.5 4.3 5.7 65.7

End Of Report